package com.project.lx.text.presenter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.MotionEvent;
import android.view.View;

import com.project.lx.text.adapter.ActMainPagerAdapter;
import com.project.lx.text.contract.IMainContract;
import com.project.lx.text.fragment.FragmentA;
import com.project.lx.text.fragment.FragmentB;
import com.project.lx.text.fragment.FragmentC;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Meteor
 * @description: MainActivity的Presenter
 * @version:
 * @date: 2016/12/28 0028 21:52
 * @company: jijiaxuan.com
 * @email: lx802315@163.com
 */
public class ActMainPresenterImpl implements IMainContract.IMainPresenter {
    private final IMainContract.IMainView view;
    private FragmentPagerAdapter pagerAdapter;

    //声明一个集合用于存放Fragment
    private List<Fragment> fragments;

    public ActMainPresenterImpl(IMainContract.IMainView view) {
        this.view = view;
        view.setPresenter(this);
    }

    @Override
    public void initData() {
        //获取显示内容的frameLayout
        ViewPager viewPagerContent = view.getmActMainVpContent();
        //初始化数据
        fragments = new ArrayList<>();
        fragments.add(new FragmentA());
        fragments.add(new FragmentB());
        fragments.add(new FragmentC());
        pagerAdapter = new ActMainPagerAdapter(view.getManager(), fragments);
        //为viewpager设置适配器
        viewPagerContent.setAdapter(pagerAdapter);
        //设置viewPager为不可滑动状态,存在主Fragment无法切换左右切换
        viewPagerContent.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;  //修改为true
            }

        });
    }

}
